package com.zyz.system.controller.question;

import com.zyz.common.core.active.Time;
import com.zyz.common.core.model.Result;
import com.zyz.common.core.model.TableDataInfo;
import com.zyz.system.model.question.dto.QuestionAddDTO;
import com.zyz.system.model.question.dto.QuestionEditDTO;
import com.zyz.system.model.question.dto.QuestionQueryDTO;
import com.zyz.system.model.question.vo.QuestionDetailVO;
import com.zyz.system.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/question")
@RestController
@Tag(name = "题目管理接口")
public class QuestionController {

    @Autowired
    private IQuestionService questionService;

    @Time
    @Operation(description = "获取题目列表")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public TableDataInfo list(QuestionQueryDTO queryDTO) {
        return questionService.list(queryDTO);
    }

    @Time
    @Operation(description = "添加题目")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Void> add (@RequestBody QuestionAddDTO queryAddDTO) {
        questionService.add(queryAddDTO);
        return Result.ok();
    }

    @Time
    @Operation(description = "根据questionId返回详情")
    @RequestMapping(value = "/detail",method = RequestMethod.GET)
    public Result<QuestionDetailVO> detail (Long questionId) {
        return Result.ok(questionService.detail(questionId));
    }

    @Time
    @Operation(description = "根据传递信息进行参数修改")
    @RequestMapping(value = "/edit",method = RequestMethod.PUT)
    public Result<Void> edit (@RequestBody QuestionEditDTO questionEditDTO) {
        questionService.edit(questionEditDTO);
        return Result.ok();
    }

//    @Time
    @Operation(description = "根据题目id删除题目")
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public Result<Void> delete (Long questionId) {
        System.out.println("questionId = " + questionId);
        questionService.delete(questionId);
        return Result.ok();
    }

}
